﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StoragePeriod.IDAL.FoodTesting;
using StoragePeriod.DALFactory;
using StoragePeriod.Model.FoodTesting;
using System.Data;

namespace StoragePeriod.BLL.FoodTesting
{
    /// <summary>
    /// DietaryFiberData
    /// </summary>
    public partial class T_DietaryFiberData
    {
        I_DietaryFiberData dal = new DataAccess<I_DietaryFiberData>().CreateInstance("FoodTesting.D_DietaryFiberData");
        public T_DietaryFiberData()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            return dal.Exists(id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(E_DietaryFiberData model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(E_DietaryFiberData model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {

            return dal.Delete(id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string idlist)
        {
            return dal.DeleteList(idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public E_DietaryFiberData GetModel(int id)
        {

            return dal.GetModel(id);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<E_DietaryFiberData> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<E_DietaryFiberData> DataTableToList(DataTable dt)
        {
            List<E_DietaryFiberData> modelList = new List<E_DietaryFiberData>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                E_DietaryFiberData model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new E_DietaryFiberData();
                    if (dt.Rows[n]["id"].ToString() != "")
                    {
                        model.id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    if (dt.Rows[n]["RawID"].ToString() != "")
                    {
                        model.RawID = int.Parse(dt.Rows[n]["RawID"].ToString());
                    }
                    model.RawName = dt.Rows[n]["RawName"].ToString();
                    model.MBR1 = dt.Rows[n]["MBR1"].ToString();
                    model.MBR2 = dt.Rows[n]["MBR2"].ToString();
                    model.MPB = dt.Rows[n]["MPB"].ToString();
                    model.MAB = dt.Rows[n]["MAB"].ToString();
                    model.MB = dt.Rows[n]["MB"].ToString();
                    model.MR1 = dt.Rows[n]["MR1"].ToString();
                    model.MR2 = dt.Rows[n]["MR2"].ToString();
                    model.MP = dt.Rows[n]["MP"].ToString();
                    model.MA = dt.Rows[n]["MA"].ToString();
                    model.M1 = dt.Rows[n]["M1"].ToString();
                    model.M2 = dt.Rows[n]["M2"].ToString();
                    model.Result = dt.Rows[n]["Result"].ToString();
                    if (dt.Rows[n]["FoodTime"].ToString() != "")
                    {
                        model.FoodTime = DateTime.Parse(dt.Rows[n]["FoodTime"].ToString());
                    }
                    if (dt.Rows[n]["FoodNum"].ToString() != "")
                    {
                        model.FoodNum = int.Parse(dt.Rows[n]["FoodNum"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        /// <summary>
        /// 根据原料ID和检测时间 删除检测记录
        /// </summary>
        /// <param name="eVcData">要删除的检测记录</param>
        /// <returns></returns>
        public int RemoveByTime(E_DietaryFiberData eDietaryFiberData)
        {
            return dal.RemoveByTime(eDietaryFiberData);
        }

        /// <summary>
        /// 删除某一次检测记录
        /// </summary>
        /// <param name="eVcData">要删除的检测记录</param>
        /// <returns></returns>
        public int RemoveByFoodNum(E_DietaryFiberData eDietaryFiberData)
        {
            return dal.RemoveByFoodNum(eDietaryFiberData);
        }
        #endregion  Method
    }
}
